/*************************************************************************
 *                                                                       *
 * This file is part of the FreeMAPs distribution.  For full copyright   *
 * information, see COPYRIGHT and COPYING.LESSER.                        *
 *                                                                       *
 * Author:           sqbang                                              *
 * Email:            sqbang@ustc.edu                                     *
 * Date:             2017.03.31                                          *
 *                                                                       *
 *************************************************************************/

//declaration header
#include "COMMON/tbox/DatabaseBox.h"

namespace FreeMAPs
{

DatabaseBox::DatabaseBox()
{
    d_data.d_dimension = 0;
    for (int i = 0; i < FREEMAPS_DIM; ++i) {
        d_data.d_lo[i] = d_data.d_hi[i] = 0;
    }
}



DatabaseBox::DatabaseBox(
    const DatabaseBox& box)
{
    d_data = box.d_data;
}



DatabaseBox::DatabaseBox(
    const int dim,
    const int* lower,
    const int* upper)
{
    d_data.d_dimension = dim;

    for (int i = 0; i < d_data.d_dimension; i++)
    {
        d_data.d_lo[i] = lower[i];
        d_data.d_hi[i] = upper[i];
    }

    for (int j = d_data.d_dimension; j < FREEMAPS_DIM; j++)
    {
        d_data.d_lo[j] = 0;
        d_data.d_hi[j] = 0;
    }
}



DatabaseBox::~DatabaseBox()
{}



DatabaseBox&
DatabaseBox::operator = (
    const DatabaseBox& box)
{
    d_data = box.d_data;
    return *this;
}



bool
DatabaseBox::empty() const
{
    bool is_empty = (d_data.d_dimension == 0 ? true : false);
    for (int i = 0; i < d_data.d_dimension; i++) {
        if (d_data.d_hi[i] < d_data.d_lo[i]) is_empty = true;
    }
    return is_empty;
}



bool
DatabaseBox::operator == (
    const DatabaseBox& box) const
{
    bool equals = (d_data.d_dimension == box.d_data.d_dimension);
    for (int i = 0; i < d_data.d_dimension; i++)
    {
        if (d_data.d_lo[i] != box.d_data.d_lo[i])
        {
            equals = false;
        }

        if (d_data.d_hi[i] != box.d_data.d_hi[i])
        {
            equals = false;
        }
    }
    return equals;
}

}
